package serv

import (
	"context"
	"generate_grom_mode_and_dao/service/genertategrom/api/internal/svc"
	"generate_grom_mode_and_dao/service/genertategrom/api/model"
	"github.com/tal-tech/go-zero/core/logx"
)

type ConfigService interface {
}
type defaultConfigService struct {
	logx.Logger
	ctx         context.Context
	svcCtx      *svc.ServiceContext
	TableName   string
	Readonly    bool
	PackageName string
	Columns     []model.InformationSchemaColumns
	Columns2    []model.InformationSchemaColumns2
}

func NewConfigService(ctx context.Context, svcCtx *svc.ServiceContext) *defaultConfigService {
	return &defaultConfigService{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (s *defaultConfigService) PrimaryColumnDataType() string {
	serviceDatabase := NewDatabaseService(s.ctx, s.svcCtx)
	for _, column := range s.Columns {
		if serviceDatabase.IsPrimary(column) {
			return serviceDatabase.JavaType(column)
		}
	}

	return ""
}

func (s *defaultConfigService) HasDelStatus() bool {
	serviceDatabase := NewDatabaseService(s.ctx, s.svcCtx)
	for _, column := range s.Columns {
		if serviceDatabase.IsDelStatus(column) {
			return true
		}
	}

	return false
}

func (s *defaultConfigService) HasDecimalType() bool {
	serviceDatabase := NewDatabaseService(s.ctx, s.svcCtx)
	for _, column := range s.Columns {
		if serviceDatabase.IsDecimalType(column) {
			return true
		}
	}

	return false
}

func (s *defaultConfigService) HasDateType() bool {
	serviceDatabase := NewDatabaseService(s.ctx, s.svcCtx)
	for _, column := range s.Columns {
		if serviceDatabase.IsDateType(column) {
			return true
		}
	}
	return false
}

func (s *defaultConfigService) HasEnterpriseId() bool {
	return s.HasColumn("enterprise_id")
}

func (s *defaultConfigService) HasCode() bool {
	return s.HasColumn("code")
}

func (s *defaultConfigService) HasStatus() bool {
	return s.HasColumn("status")
}

func (s *defaultConfigService) HasColumn(name string) bool {
	for _, column := range s.Columns {
		if column.ColumnName == name {
			return true
		}
	}
	return false
}
